package com.le.tester.leetcode;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;

/**
 * 描述：查找字符串中是不是有这个字符串
 */
public class FindStrStr {
    public int strStr(String haystack, String needle) {
        if (!haystack.contains(needle)) {
            return -1;
        }
        String[] splits = haystack.split(needle);
        String resultStr = Arrays.toString(splits).replace("[", "").replace("]", "");
        if (splits.length == 0 || "".equals(needle)) {
            return 0;
        }
        if (resultStr.contains(",")) {
            return resultStr.indexOf(",") - 1;
        } else {
            return resultStr.length();
        }

    }

    public static void main(String[] args) {
        FindStrStr findStrStr = new FindStrStr();
        int i = findStrStr.strStr("mississippi", "pi");
        System.out.println(i);
    }
}
